package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.entity.Categorys;

import java.util.List;

/**
 * Created by DJMoving on 2017/4/22 0022.
 */

public class Category_adapter extends BaseAdapter {
    // 定义Context
    private LayoutInflater mInflater;
    private List<Categorys.DataBean.GoodsBean> list;
    private Context context;

    public Category_adapter(Context context, List<Categorys.DataBean.GoodsBean> list) {
        mInflater = LayoutInflater.from(context);
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        if (list != null && list.size() > 0)
            return list.size();
        else
            return 0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final MyView view;
        if (convertView == null) {
            view = new MyView();
            convertView = mInflater.inflate(R.layout.list_right_item, null);
            view.icon = (ImageView) convertView.findViewById(R.id.typeicon);
            view.name = (TextView) convertView.findViewById(R.id.typename);
            convertView.setTag(view);
        } else {
            view = (MyView) convertView.getTag();
        }
        if (list != null && list.size() > 0) {
            view.name.setText(list.get(position).getClassname());
            view.icon.setImageResource(R.mipmap.store_back);
        }else{
            view.name.setText("哈哈");
        }

        return convertView;
    }


    private class MyView {
        private ImageView icon;
        private TextView name;
    }

}
